package chenji.dailykit.ItemEditor.operationnode.nodes;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import chenji.dailykit.Main;
import chenji.dailykit.ItemEditor.ItemEditor;
import chenji.dailykit.ItemEditor.operationnode.OperationNode;
import chenji.dailykit.ItemEditor.operationnode.SimpleItemStack;

public class EnchantmentAddEditor extends OperationNode {
	Inventory i;
	int state;
	int temp;

	public EnchantmentAddEditor(ItemStack i, ItemEditor e, Player p) {
		super(i, e, p, true, 2);
	}

	@Override
	public void setInventory(Inventory inv) {
		this.chengePage1(1, inv);
		this.chengePage(1);
		this.i = inv;
	}

	@Override
	public void Click(int slot) {
		System.out.println(this.getNowPage());
		System.out.println(slot);
		if (this.getNowPage() == 2) {
			switch (slot) {
			case 28:
				this.temp = 21;
				break;
			case 29:
				this.temp = 32;
				break;
			case 30:
				this.temp = 33;
				break;
			case 31:
				this.temp = 34;
				break;
			case 32:
				this.temp = 35;
				break;
			case 33:
				this.temp = 48;
				break;
			case 34:
				this.temp = 49;
				break;
			case 37:
				this.temp = 50;
				break;
			case 38:
				this.temp = 51;
				break;
			case 39:
				this.temp = 61;
				break;
			case 40:
				this.temp = 62;
				break;
			case 41:
				this.getItemEditor().chengeEnchantmentEditor();
				return;
			default:
				return;
			}
		}
		if (this.getNowPage() == 1) {
			switch (slot) {
			case 28:
				this.temp = 0;
				break;
			case 29:
				this.temp = 1;
				break;
			case 30:
				this.temp = 2;
				break;
			case 31:
				this.temp = 3;
				break;
			case 32:
				this.temp = 4;
				break;
			case 33:
				this.temp = 5;
				break;
			case 34:
				this.temp = 6;
				break;
			case 37:
				this.temp = 7;
				break;
			case 38:
				this.temp = 8;
				break;
			case 39:
				this.temp = 16;
				break;
			case 40:
				this.temp = 17;
				break;
			case 41:
				this.temp = 18;
				break;
			case 42:
				this.temp = 19;
				break;
			case 43:
				this.temp = 20;
				break;
			default:
				return;
			}
		}
		this.getPlayer().sendMessage("&a[ItemEditor] &c请输入附魔等级。");
		this.getItemEditor().getChat();
		this.getPlayer().closeInventory();
		return;
	}

	protected void chengePage1(int page, Inventory inv) {

		if (page == 1) {
			inv.setItem(28, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a保护 §c附魔" }, " "));
			inv.setItem(29, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a火焰保护 §c附魔" }, " "));
			inv.setItem(30, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a掉落保护 §c附魔" }, " "));
			inv.setItem(31, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a爆炸保护 §c附魔" }, " "));
			inv.setItem(32, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a弹射物保护 §c附魔" }, " "));
			inv.setItem(33, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a水下呼吸 §c附魔" }, " "));
			inv.setItem(34, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a水下速掘 §c附魔" }, " "));
			inv.setItem(37, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a荆棘 §c附魔" }, " "));
			inv.setItem(38, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a深海探索者 §c附魔" }, " "));
			inv.setItem(39, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a锋利§c附魔" }, " "));
			inv.setItem(40, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a亡灵杀手§c附魔" }, " "));
			inv.setItem(41, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a节肢杀手§c附魔" }, " "));
			inv.setItem(42, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a击退§c附魔" }, " "));
			inv.setItem(43, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a火焰附加§c附魔" }, " "));
			return;
		}
		if (page == 2) {
			inv.setItem(28, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a掠夺 §c附魔" }, " "));
			inv.setItem(29, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a效率 §c附魔" }, " "));
			inv.setItem(30, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a精准采集 §c附魔" }, " "));
			inv.setItem(31, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a耐久 §c附魔" }, " "));
			inv.setItem(32, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a时运 §c附魔" }, " "));
			inv.setItem(33, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a力量 §c附魔" }, " "));
			inv.setItem(34, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a冲击 §c附魔" }, " "));
			inv.setItem(37, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a火矢 §c附魔" }, " "));
			inv.setItem(38, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a无限 §c附魔" }, " "));
			inv.setItem(39, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a海之眷顾§c附魔" }, " "));
			inv.setItem(40, new SimpleItemStack(Material.BOOK, new String[] { "§c添加 §a钓饵§c附魔" }, " "));
			inv.setItem(41, new SimpleItemStack(Material.BOOK, new String[] { "§c返回" }, " "));
		}
	}

	@Override
	public void upPage() {

		if (this.getNowPage() == 1) {
			this.getItemEditor().clearOperationNode();
			this.chengePage1(2, this.i);
			this.chengePage(2);
		}
	}

	@Override
	public void downPage() {

		if (this.getNowPage() == 2) {
			this.getItemEditor().clearOperationNode();
			this.chengePage1(1, this.i);
			this.chengePage(1);
		}
	}

	@SuppressWarnings("deprecation")
	@Override
	public boolean setChat(String m) {
		int i;
		try {
			i = Integer.valueOf(m);
		} catch (Exception e) {
			this.getPlayer().sendMessage("§c错误，你输入的不是一个数字。请重新输入。");
			return true;
		}
		ItemStack item = this.getItem();
		item.addUnsafeEnchantment(Enchantment.getById(this.temp), i);

		Main.getItemEditorManager().setItem(this.getPlayer(), item);
		this.getItemEditor().chengeEnchantmentEditor();
		this.getItemEditor().openInventory();
		return true;
	}
}
